package hsl.study.videocapturesystem.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @Author: hsl
 * @CreateDate: 2025/7/29 10:05
 * @Version: 1.0
 */

@Configuration
public class ThreadPoolExecutorConfig {

    @Value("${ThreadPoolExecutor.corePoolSize}")
    private int corePoolSize;

    @Value("${ThreadPoolExecutor.maximumPoolSize}")
    private int maximumPoolSize;

    @Value("${ThreadPoolExecutor.keepAliveTime}")
    private long keepAliveTime;

    @Value("${ThreadPoolExecutor.unit}")
    private TimeUnit unit;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(
                corePoolSize,
                maximumPoolSize,
                keepAliveTime,
                unit,
                new LinkedBlockingQueue<>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }

}
